//
//  LazyVGridView.swift
//  波形图demo
//
//  Created by apple on 2021/2/25.
//

import SwiftUI

struct Cell: Equatable {
    var id: Int
    var name: String
}

struct LazyVGridView: View {
    var body: some View {
        
        var columns: [GridItem] =
          Array(repeating: .init(.flexible()), count: 2)

        
        var listData = [Cell(id: 0, name: "value 1"),
                        Cell(id: 1, name: "value 2"),
                        Cell(id: 2, name: "value 3"),
                        Cell(id: 3, name: "value 2"),
                        Cell(id: 4, name: "value 3"),
                        Cell(id: 5, name: "value 2"),
                        Cell(id: 6, name: "value 3"),
                        Cell(id: 7, name: "value 2"),
                        Cell(id: 8, name: "value 3"),
                        Cell(id: 9, name: "value 2"),
                        Cell(id: 10, name: "value 3"),
                        Cell(id: 11, name: "value 2"),
                        Cell(id: 12, name: "value 3"),
                        Cell(id: 13, name: "value 2"),
                        Cell(id: 14, name: "value 3"),
                        Cell(id: 15, name: "value 2"),
                        Cell(id: 16, name: "value 3"),
                        Cell(id: 17, name: "value 2"),
                        Cell(id: 18, name: "value 3"),
                        Cell(id: 19, name: "value 2"),
                        Cell(id: 20, name: "value 3"),
                        Cell(id: 21, name: "value 2"),
                        Cell(id: 22, name: "value 3"),
                        Cell(id: 23, name: "value 2"),
                        Cell(id: 24, name: "value 3"),
                        Cell(id: 25, name: "value 2"),
                        Cell(id: 26, name: "value 3")]

        ScrollView(.vertical) {

            LazyVGrid(columns: columns) {

                ForEach (listData, id: \.id) { index in
                    
                    NavigationLink(
                        destination: Text("Destination"),
                        label: {
                            VStack (){
                                Text("你好\(index.name)")
                                Text("你好\(index.id)")
                            }
                            .frame(minWidth: 200, idealWidth: 200, maxWidth: .infinity, minHeight: 200, idealHeight: 200, maxHeight: .infinity, alignment: .center)
                            .border(Color.gray)
                            
                        })
                }
            }
        }
    }
}

struct LazyVGridView_Previews: PreviewProvider {
    static var previews: some View {
        LazyVGridView()
    }
}
